new Vue({
  el: "#app",
  data() {
    return {
      form: {
        News_Type: "0", //type 默认空是全部
        News_Name: "",
        Row_Status: "-", //状态
        SQLSerialNumber: "P_news_info_1",
        PaginationNumber: 1, //页数
        RowAmount: 10, //每页数据条数
        Condition: "",
        ExtensionCondition: "",
      },
      tableData: [], //表格数据
      total: 1,
      multipleSelection: [],
      News_Type: [
        {
          value: "0",
          label: "产业技术",
        },
        {
          value: "1",
          label: "文化宣传",
        },
        {
          value: "2",
          label: "产品展示",
        },
        {
          value: "3",
          label: "政策",
        },
        {
          value: "4",
          label: "法规",
        },
      ],
    };
  },
  computed: {
    News_Label() {
      if (getQueryObject().News_Type) {
        this.form.News_Type = getQueryObject().News_Type;
      }
      let ObjNew_Type = this.News_Type.filter(
        (i) => i.value == this.form.News_Type
      )[0];
      return ObjNew_Type.label;
    },
  },
  mounted() {
    $("title").text(this.News_Label);
    this.getList(this.form);
  },
  methods: {
    onSerach() {
      //查询方法
      this.form.PaginationNumber = 1;
      this.getList(this.form);
    },
    handleSizeChange(val) {
      this.form.PaginationNumber = 1;
      this.form.RowAmount = val;
      this.getList(this.form);
    },
    handleCurrentChange(val) {
      this.form.PaginationNumber = val;
      this.getList(this.form);
    },
    getList(form) {
      //换页方法
      const that = this;
      let data = deepClone(form);
      data.Condition = window.btoa(
        unescape(
          encodeURIComponent("%" + data.News_Name + "%," + data.News_Type)
        )
      );
      if (data.Row_Status != "-") {
        data.ExtensionCondition = window.btoa(
          unescape(
            encodeURIComponent(" AND Row_Status = '" + data.Row_Status + "'")
          )
        );
      }
      $.ajax({
        headers: requestHeaders(),
        type: "POST",
        url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        data,
        success: function (Result) {
          console.log(Result);

          that.tableData = Result.Rows;
          that.total = Result.TotalRows;
        },
        // complete: function (XMLHttpRequest) {
        //   requestPretreatment(XMLHttpRequest);
        // },
        dataType: "json",
      });
    },
    Add() {
      window.location.href =
        "./Add.html?News_Type=" + getQueryObject().News_Type;
    },
    handleOperate(command, row) {
      if (command == "show") {
        this.Show(row);
      } else if (command == "approve") {
        this.Remove(row, "1");
      } else if (command == "refuse") {
        this.Remove(row, "2");
      } else if (command == "approve2") {
        this.Remove(row, "0");
      } else if (command == "edit") {
        this.Edit(row);
      } else if (command == "remove") {
        this.Remove(row, "3");
      }
    },
    Edit(row) {
      console.log(row);

      sessionStorage.setItem("News_SerialNumber", row.News_SerialNumber);
      window.location.href =
        "./Edit.html?News_Type=" + getQueryObject().News_Type;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    shanchulis() {
      let a = [];
      console.log(this.multipleSelection);
      this.multipleSelection?.forEach((element) => {
        console.log(element);
        element.Row_Status = "3";
        a.push(element);
      });
      console.log(a);
      let lJSONObject_news_info = new Object();
      lJSONObject_news_info.news_info = a; //换表
      let lJSONObject_DataSet = new Object(); // Modify
      lJSONObject_DataSet.Modify = lJSONObject_news_info; //换表
      const _this = this;
      $.ajax({
        // headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
          if (Result.Status === "success") {
            _this.$message({
              message: "删除成功",
              type: "success",
            });
            // window.history.go(-1);
            _this.getList(_this.form);
          } else {
            _this.$message.error("提交失败，请稍后再试");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    shenhelis() {
      let a = [];
      console.log(this.multipleSelection);
      this.multipleSelection?.forEach((element) => {
        console.log(element);
        element.Row_Status = "1";
        a.push(element);
      });
      console.log(a);
      let lJSONObject_news_info = new Object();
      lJSONObject_news_info.news_info = a; //换表
      let lJSONObject_DataSet = new Object(); // Modify
      lJSONObject_DataSet.Modify = lJSONObject_news_info; //换表
      const _this = this;
      $.ajax({
        // headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
          if (Result.Status === "success") {
            _this.$message({
              message: "提交成功",
              type: "success",
            });
            _this.getList(_this.form);
            // window.history.go(-1);
          } else {
            _this.$message.error("提交失败，请稍后再试");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    Show(row) {
      window.sessionStorage.setItem("News_SerialNumber", row.News_SerialNumber);
      window.location.href =
        "./NewsDetail.html?News_Type=" + getQueryObject().News_Type;
    },
    Remove(data, Row_Status) {
      const that = this;
      let label =
        Row_Status == "0"
          ? "重新审核"
          : Row_Status == "1"
          ? "通过"
          : Row_Status == "2"
          ? "拒绝"
          : "删除";
      this.$confirm(
        "此操作将" + label + "该" + this.News_Label + ", 是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          let row = deepClone(data);
          row.Row_Status = Row_Status;
          $.ajax({
            headers: requestHeaders(),
            url: `${BASE_URL2}/generalBusiness/generalSave`,
            type: "POST",
            data: {
              Data: JSON.stringify({
                Modify: { news_info: [row] },
              }),
            },
            success: function (res) {
              if (res.Status === "success") {
                that.$message({
                  type: "success",
                  message: label + "成功!",
                });
              } else {
                that.$message.error(label + "失败，请稍后再试");
              }
              that.getList(that.form);
            },
            // complete: function (XMLHttpRequest) {
            //   that.loading = false;
            //   requestPretreatment(XMLHttpRequest);
            // },
            dataType: "json",
          });
        })
        .catch(() => {});
    },
  },
});
